package com.backstage.lyorder.controller;


import com.backstage.lyorder.pojo.MobileEndOrder;
import com.backstage.lyorder.pojo.QueryData;
import com.backstage.lyorder.service.MobileEndOrderService;
import com.backstage.utils.R;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 订单表 前端控制器
 * </p>
 *
 * @author sakura
 * @since 2022-12-13
 */
@RestController
@RequestMapping("/order")
@CrossOrigin
public class MobileEndOrderController {
    @Autowired
    private MobileEndOrderService orderService;

    @PostMapping("list")
    public R getPageList(@RequestBody QueryData queryData){
        Page<MobileEndOrder> page = new Page<>(queryData.getCp(), queryData.getLs());
        QueryWrapper<MobileEndOrder> queryWrapper = new QueryWrapper<>();
        if (!StringUtils.isEmpty(queryData.getOrderIdkw()))
            queryWrapper.eq("orderid",queryData.getOrderIdkw());
        if (!StringUtils.isEmpty(queryData.getNamekw()))
            queryWrapper.eq("name",queryData.getNamekw());
        if (!StringUtils.isEmpty(queryData.getPhonekw()))
            queryWrapper.eq("tel",queryData.getPhonekw());
        queryWrapper.eq("status",queryData.getStatus());
        orderService.page(page,queryWrapper);
        return R.ok().data("items",page.getRecords()).data("total",page.getTotal()).data("current",page.getCurrent())
                .data("pagesize",page.getSize());
    }
}

